package ca.starfarer.kobold.model;

/**
 * @author Kevin
 */
public abstract class DBObject {

    private Long id;

    protected DBObject() { }

    public Long getId() {
        return id;
    }

    public void setId(Long id) {
        this.id = id;
    }

    @Override
    public boolean equals(Object obj) {
        if (obj == this) {
            return true;    // Trivial
        }
        if (id == null) {
            return false;   // We have no identity yet
        }
        if (obj != null && obj.getClass() == this.getClass()) {
            DBObject that = (DBObject) obj;
            return this.id.equals(that.id);     // Check DB identity
        }
        return false;
    }

    @Override
    public int hashCode() {
        return (id != null) ? id.hashCode() : 0;
    }

    @Override
    public String toString() {
        return getClass() + "[" + paramString() + "]";
    }

    protected String paramString() {
        return "id=" + id;
    }
}
